#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    int pid = 0;
    int i = 0;
    
    printf("parent = %d, ppid = %d, pgid = %d\n", getpid(), getppid(), getpgrp());
    
    while( i < 5 ) {
        if( (pid = fork()) > 0 ) {
            printf("new: %d\n", pid);
        } else if( pid == 0 ) {
            sleep(1);
            printf("child = %d, ppid = %d, pgid = %d\n", getpid(), getppid(), getpgrp());
            sleep(60);
            printf("last -- pgid = %d\n", getpgrp());
            break;
        } else {
            printf("fork error...\n");
        }
        
        i++;
    }
    
    if( pid ) {
        sleep(60);
    }

    return 0;
}

